// __PUBLIC__/js/page/cms/block/contentlist
require(['../../common'], function() {
  require(['block.contentlist'])
})

define('block.contentlist', [
  'jquery',
  'page/grid'
], function($, Grid) {
  'use strict';

  var $table = $('.table')
  var mygrid = new Grid($table)
  mygrid.init();

  function del(selected) {
    var id = $('#id').val()
    $.post(APP + '?app=cms&m=Block&a=delBlockContent', {
      id: id,
      contentid: selected.id.join()
    })
      .done(function(data) {
        if (data == 1) {
          mygrid.del(selected.index)
        } else {
          alert('删除失败')
        }
      })
  }

  $(document)
  // 删除当前行
  .on('click', '.A_del', function(e) {
    e.preventDefault()
    if (confirm('确定删除已选择的内容')) {
      var current = mygrid.getCurrent(this)
      var selected = {
        id: [current.id],
        index: [current.index]
      }
      del(selected)
    }
  })
    .on('click', 'img[showbigimage="true"]', function(e) {
      e.preventDefault()
      var imageurl = $(this).attr('src')
      if (imageurl) {
        $('#detailImg').attr('src', imageurl)
        $('#details').css('top', e.pageY).css('left', e.pageX).css('display', 'block')
      }
    })
    .on('click', '#details', function(e) {
      e.preventDefault()
      $(this).css('display', 'none')
    })
})